import os
import uuid

from pathlib import Path

from jinja2 import Environment, FileSystemLoader


def template_render(filename):
    file = Path(filename)

    if file.is_file():
        loader = FileSystemLoader(os.getcwd())
        env = Environment(
            loader=loader,
            variable_start_string='<<',
            variable_end_string='>>'
        )

        context = {
            'appName': '{{ cookiecutter.app }}'
        }

        template = env.get_template(file.as_posix())
        content = template.render(context)

        with open(file.as_posix(), 'w', encoding='utf-8') as f:
            f.write(content + '\n')


if __name__ == '__main__':
    template_render('src/utils/config.ts')
